﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace wfTree
{
	public partial class Form1 : Form
	{
		FtPerson _person = new FtPerson();
		public Form1()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{

			Program.FUserDetail.Relation = Relationship.Primary;
			Program.FUserDetail.ShowDialog(this);
			//frmUserDetail fud = new frmUserDetail();
			//fud.Relation = Relationship.Primary;
			//fud.ShowDialog(this);
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			LoadUpPerson(1);
		}

		public void LoadUpPerson(long personId, bool OnlyIfDifferent=false)
		{
			if (OnlyIfDifferent && _person.PriPerson.PersonId == personId)
				return;

			_person.LoadPerson(personId);

			if (_person.Exists)
			{
				ctlPriPerson.Person = _person.PriPerson;
				if (_person.HasSpouse)
					ctlPriPerson.Spouse = _person.Spouse;
				ctlPriPerson.UpdatePerson();

				if (_person.Father.Status == 2)
				{
					ctlAddFather.Visible = true;
					ctlAddFather.Text = "Add Father";
					ctlAddFather.RelatedTo = _person.PriPerson;
					ctlAddFather.Relation = Relationship.Father;
					ctlParent1.Person = null;
					ctlParent1.UpdatePerson();
				}
				else
				{
					ctlAddFather.Visible = false;
					if (_person.Father.SpousePersonId == _person.Mother.PersonId)
						ctlParent1.UpdatePerson(_person.Father, _person.Mother);
					else
						ctlParent1.UpdatePerson(_person.Father);
				}

				if (_person.Mother.Status == 2)
				{
					ctlAddMother.Visible = true;
					ctlAddMother.Text = "Add Mother";
					ctlAddMother.RelatedTo = _person.PriPerson;
					ctlAddMother.Relation = Relationship.Mother;
					ctlParent2.Person = null;
					ctlParent2.UpdatePerson();
				}
				else
				{
					ctlAddMother.Visible = false;
					if (_person.Mother.PersonId == _person.Father.SpousePersonId)
					{
						ctlParent2.Visible = false;
					}
					else
					{
						ctlParent2.UpdatePerson(_person.Mother);
					}
				}
			}
		}
	}
}
